//
//  oldActivityDetailViewController.m
//  laonianbang
//
//  Created by 勇拓 李 on 18/4/3.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldActivityDetailViewController.h"
#import "oldActivityDetailHeaderView.h"
#import "oldMomentCommentTableViewCell.h"
#import "oldActivityAppointmentViewController.h"

@interface oldActivityDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    NSInteger pageNo;
}
@property (weak, nonatomic) IBOutlet UITableView *table_view;
@property (weak, nonatomic) IBOutlet UIButton *btn_commit;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomView_height;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

static NSString *const identifier = @"oldMomentCommentTableViewCell";

@implementation oldActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

#pragma mark - initView
- (void)initView
{
    self.navigationItem.title = @"活动详情";
    
    [self initTableView];
    
    _bottomView.hidden = YES;
    _bottomView_height.constant = 0;
    _btn_commit.layer.cornerRadius = 6.f;
}

- (void)initTableView
{
    [self.table_view registerNib:[UINib nibWithNibName:identifier bundle:nil] forCellReuseIdentifier:identifier];
    
    self.table_view.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//隐藏空的 cell
    self.table_view.delegate = self;
    self.table_view.dataSource = self;
    
    self.table_view.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.table_view.estimatedRowHeight = 69;
    self.table_view.rowHeight = UITableViewAutomaticDimension;
}

- (void)initHeader
{
    oldActivityDetailHeaderView *view = [[[NSBundle mainBundle] loadNibNamed:@"oldActivityDetailHeaderView" owner:self options:nil] objectAtIndex:0];
    
    CGFloat height = [view getHeight:_activity];
    
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
    
    self.table_view.tableHeaderView = header;
    view.frame = header.bounds;
    [header addSubview:view];
    
    view.activity = _activity;
}

- (void)initBottom
{
    [_btn_commit addTarget:self action:@selector(btn_commit_tapped:) forControlEvents:UIControlEventTouchDown];
    
    if ([_activity isEnded]) {
        _bottomView.hidden = YES;
        _bottomView_height.constant = 0;
    }
    else
    {
        _bottomView.hidden = NO;
        _bottomView_height.constant = 70;
    }
}

- (void)btn_commit_tapped:(id)sender
{
    oldActivityAppointmentViewController *vc = [oldActivityAppointmentViewController new];
    vc.activity = _activity;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - initData
- (void)initData
{
    [self initActivityData];
}

- (void)initActivityData
{
    [oldHub waiting:@"加载中"];
    
    WeakSelf
    
    [OLDNetWork httpRequestWithPostPut:URL_GetDetail params:@{@"aid":_activity.aid} success:^(id data) {
        [oldHub hideHUD];
        if (data) {
            weakSelf.activity = [[oldActivity alloc] initWithDictionary:data];
            [weakSelf initHeader];
            [weakSelf initBottom];
        }
    } error:^(NSString *error) {
        [oldHub warningUser:error];
    }];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if(indexPath.section == 1)
//    {
//        _selectComment = _commentArray[indexPath.row];;
//        _text_filed.placeholder = [NSString stringWithFormat:@"回复%@",_selectComment.replyUserInfo.uname];
//        [self.text_filed becomeFirstResponder];
//    }
}

@end
